package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.constant.AutoFillConstant;
import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 根据名字和类型查询
     * @return
     * @param name
     * @param type
     */
    List<Category> selectByNameAndType(String name, Integer type);

    /**
     * 根据name查询分类名的数量
     * @return
     * @param name
     */



    /**
     * 新增用户
     * @param category
     */
    @AutoFill(OperationType.INSERT)
    void insert(Category category);

    /**
     * 根据id删除分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void delete(Long id);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @Select("select * from category where type = #{type}")
    List<Category> selectByType(Integer type);

    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    /**
     * 查询名字数量,不包括自己
     * @param name
     * @param id
     * @return
     */
    @Select("select COUNT(*) from category where name = #{name} and id != #{id}")
    Integer selectByNameNotSelf(String name, Long id);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("Select * from category where id = #{id}")
    Category selectById(Long id);


    /**
     * 查询所有套餐信息
     *
     * @return {@link List}<{@link Setmeal}>
     */
    @Select("select * from category")
    List<Category> select();

    /**
     * 修改分类
     *
     *
     */

}
